package com.smart.primary.sys.ctrl;

import com.smart.primary.common.common.BaseCtrl;
import com.smart.primary.common.util.AjaxResult;
import com.smart.primary.common.util.Util;
import com.smart.primary.sys.service.DictService;
import com.smart.primary.sys.vo.Dict;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("/sys/dict")
public class DictCtrl extends BaseCtrl {

	@Autowired
	private DictService dictService;

	@RequestMapping
	public AjaxResult getList(Dict entity) throws Exception{
		List<Dict> list=dictService.queryListByPage(entity);
		return getResult(entity, list);
	}

	@RequestMapping("list")
	public List<Dict> list(Dict entity) throws Exception{
		return dictService.queryList(entity);
	}

	@RequestMapping("/save")
	public AjaxResult save(Dict entity) throws Exception{
		if(entity.getId()==null){
			dictService.insert(entity);
			return AjaxResult.updateSuccess();
		}else {
			dictService.update(entity);
			return AjaxResult.saveSuccess();
		}
	}

	@RequestMapping("/del")
	public AjaxResult del(String id) throws Exception{
		dictService.delete(id);
		return AjaxResult.deleteSuccess();
	}
}
